<?php
	$title_for_layout = $this->Sanitize->html($post['Post']['title']);
	$this->set(compact('title_for_layout')); 
?>
<div id="post-view">
<div class="post">
	<h1><?php echo $title_for_layout; ?></h1>
	<div class="meta">
		<?php
			if (!empty($post['Author'][Configure::read('Lil.authorDisplayField')])) {
				printf(__d('lil', 'Posted %1$s by %2$s', true),
					$this->Time->timeAgoInWords($post['Post']['created']),
					$post['Author'][Configure::read('Lil.authorDisplayField')]
				);
			} else {
				printf(__d('lil', 'Posted %s', true),
					$this->Time->timeAgoInWords($post['Post']['created'])
				);
			}
			
			// display list of categories
			if (!empty($post['Category'])) {
				echo ' ' . __d('lil', 'in', true) . ' ';
				
				echo $this->Text->toList(
					Set::format(
						$post, 
						$this->Html->link('%1$s', array(
							'controller' => 'posts',
							'action'     => 'index',
							'blog'       => $post['Blog']['slug'],
							'category'   => '%2$s'
						)), 
						array('Category.{n}.name', 'Category.{n}.id')
					),
					__d('lil', 'and', true)
				);
			}
			
			// show no of comments
			echo ' (';
			// this is neccessary because of i18n extraction
			$comment_count = $post['Post']['no_comments'];
			echo $this->Html->link(sprintf(
				__dn('lil', '1 comment', '%d comments', $comment_count, true), $comment_count),
				array(
					'plugin'     => 'lil',
					'controller' => 'posts',
					'action'     => 'view',
					'blog'       => $blog['Blog']['slug'],
					'post'       => $post['Post']['slug'],
					'comment'    => 'comments'
				));
			echo ')';
			
			// show "edit this post" link
			if ($this->Auth->user('id')) {
				echo ' | '.$this->Html->link(__d('lil', 'Edit this post', true), array(
					'admin'   => true,
					'action'  => 'edit',
					'blog_id' => $post['Post']['blog_id'],
					$post['Post']['id']
				));
			}
		?>
	</div>
	<div class="body">
	<?php
		echo $this->Sanitize->wpautop($post['Post']['body']);
	?>
	</div>
</div>
<div class="commentlist" id="CommentList">
	<h2><?php __d('lil', 'Comments'); ?></h2><a name="comments"></a>
<cake:nocache>
<?php 
	if (empty($post['Comment'])) {
		if ($post['Post']['allow_comments']) {
?>
	<div id="NoComments"><?php __d('lil', 'No comments yet. Please do add yours.'); ?></div>
<?php
		}
	} else {
	$i = 1;
	foreach($post['Comment'] as $comment) {
?>
	<div class="comment" id="c<?php echo $comment['id']; ?>">
		<div class="meta">
			<span class="commentnumber"><a href="#c<?php echo $comment['id']; ?>"><?php echo $i++; ?></a></span>
			<span class="poster"><?php echo (strlen($comment['url'])>0) ? $this->Html->link($comment['author'], $comment['url']) : $comment['author']; ?></span>
			<?php __d('lil', 'said'); ?> <?php echo $this->Time->timeAgoInWords($comment['created']); ?>:
		</div>
		<div class="message">
			<?php echo $this->Sanitize->wpautop($comment['body']); ?>
		</div>
	</div>
<?php }} ?>
</cake:nocache>
</div>

<?php if ($post['Post']['allow_comments']) { ?>
	<div class="form" id="CommentForm">
		<a name="addcomment"></a>
		<h2 id="PostComment"><?php __d('lil', 'Leave a Comment'); ?></h2>
		<?php
			echo $form->create('Comment', array('url'=>Router::url(null, true).'#addcomment'));
			echo $form->hidden('post_id', array('value'=>$post['Post']['id']));
			echo $form->input('author', array('label'=>__d('lil', 'Author', true).':', 'error'=> __d('lil', 'Author is required.', true)));
			echo $form->input('email', array('label'=>__d('lil', 'Email', true).':', 'error'=> __d('lil', 'Email in proper form is required.', true)));
			echo $form->input('url', array('label'=>__d('lil', 'Url', true).':'));
			echo $form->input('body', array('label'=>__d('lil', 'Body', true).':', 'error'=> __d('lil', 'Body is required.', true)));
			echo $form->submit(__d('lil', 'Add my comment', true));
			echo $form->end();
		?>
		<div id="FormNote"><?php __d('lil', 'Please be respectful; your comment my be edited or marked as spam, if necessary.'); ?></div>
	</div>
<?php } else { ?>
	<div id="CommentsClosed"><?php __d('lil', 'Sorry, comments are closed for this post. If you have any further questions or comments, feel free to contact us.');?></div>
<?php } ?>
</div>